package com.industrial.premu.service.impl;

import com.alibaba.fastjson2.writer.ObjectWriterCreator;
import com.fasterxml.jackson.databind.node.DoubleNode;
import com.industrial.premu.domain.vo.BgRespResultVo;
import com.industrial.premu.mapper.PreMuGenChartsMapper;
import com.industrial.premu.service.IPreMuGenChartsService;
import org.apache.commons.lang3.StringUtils;
import com.industrial.premu.vo.PreMuChartsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class PreMuGenChartsServiceImpl implements IPreMuGenChartsService {

    @Autowired
    private PreMuGenChartsMapper preMuGenChartsMapper;

    /**
     * <p>
     * 查询规上工业企业"亩产效益"评价结果分布图
     * </p>
     *
     * @return
     */
    @Override
    public List<Map<String, String>> queryGsCompanyResult() {
        List<Map<String, String>> resultList = preMuGenChartsMapper.queryGsCompanyResult();
        //重新修改显示的名称
        for(Map<String, String> item : resultList){
            String mjLevel = item.get("name");
            String tempMjLevel = mjLevel;
            if(StringUtils.equals(mjLevel,"A")){
                tempMjLevel = "A类(优先发展类)";
            }else if(StringUtils.equals(mjLevel,"B")){
                tempMjLevel = "B类(支持发展类)";
            }else if(StringUtils.equals(mjLevel,"C")){
                tempMjLevel = "C类(提升发展类)";
            }else if(StringUtils.equals(mjLevel,"D")){
                tempMjLevel = "D类(限制发展类)";
            }
            item.put("name",tempMjLevel);
        }
//        return preMuGenChartsMapper.queryGsCompanyResult();
        return resultList;
    }


    public Map<String, Object> getRdFund() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.rdFund();
        BigDecimal sum = null;
        BigDecimal avg = null;

        List<PreMuChartsVo> chartsVoAllShengList= preMuGenChartsMapper.rdFundAllSheng();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        if(chartsVoList == null || chartsVoList.isEmpty()){
            result.put("xAxis",xAxis);
            result.put("yAxis",yAxis);

            result.put("avg",avg);
            return  result;
        }


        if(chartsVoAllShengList!=null&&chartsVoAllShengList.size()>0){
            sum = chartsVoAllShengList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
        }
        avg=sum.divide(BigDecimal.valueOf(16),2,BigDecimal.ROUND_HALF_UP);




        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();
            xAxis.add(cityName);
            yAxis.add(indexNum);
        }
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);

        result.put("avg",avg);
//        result.put("cityList",chartsVoList);
        return  result;
    }

    @Override
    public Map<String, Object> getFunding() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.funding();
        BigDecimal sum = null;
        BigDecimal avg = null;

        List<PreMuChartsVo> chartsVoAllShengList= preMuGenChartsMapper.fundingAllSheng();

        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        if(chartsVoAllShengList == null || chartsVoAllShengList.isEmpty()){
            result.put("xAxis",xAxis);
            result.put("yAxis",yAxis);

            result.put("avg",avg);

            return  result;
        }


        if(chartsVoAllShengList!=null&&chartsVoAllShengList.size()>0){
            sum = chartsVoAllShengList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
        }
        avg=sum.divide(BigDecimal.valueOf(16),2,BigDecimal.ROUND_HALF_UP);



        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();
            BigDecimal indexNumBigDecimal = new BigDecimal(indexNum);
            indexNumBigDecimal = indexNumBigDecimal.divide(BigDecimal.valueOf(100L),2,RoundingMode.HALF_UP);
            xAxis.add(cityName);
            yAxis.add(indexNumBigDecimal.toString());
        }
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);

        result.put("avg",avg);
//        result.put("cityList",chartsVoList);
        return  result;
    }

    @Override
    public Map<String, Object> getPollution() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.pollution();
        BigDecimal sum = null;
        BigDecimal avg = null;
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        if(chartsVoList == null || chartsVoList.isEmpty()){
            result.put("xAxis",xAxis);
            result.put("yAxis",yAxis);

            result.put("avg",avg);

            return  result;
        }


        //查询全省的单位污染物排放销售
        List<PreMuChartsVo> chartsVoShengList= preMuGenChartsMapper.pollutionAllSheng();
        if(chartsVoShengList!=null&&chartsVoShengList.size()>0){
            sum = chartsVoShengList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
        }
        avg=sum.divide(BigDecimal.valueOf(16),2,BigDecimal.ROUND_HALF_UP);


        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();
            xAxis.add(cityName);
            yAxis.add(indexNum);
        }
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);

        result.put("avg",avg);
//        result.put("cityList",chartsVoList);
        return  result;
    }

    @Override
    public Map<String, Object> getTax() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.tax();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        BigDecimal sum = null;
        BigDecimal avg = null;
        if(chartsVoList == null || chartsVoList.isEmpty()){
            result.put("xAxis",xAxis);
            result.put("yAxis",yAxis);

            result.put("avg",avg);
            return  result;
        }
        List<PreMuChartsVo> chartsVoAllShengList= preMuGenChartsMapper.taxAllSheng();

        if(chartsVoAllShengList!=null&&chartsVoAllShengList.size()>0){
            sum = chartsVoAllShengList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
        }
        avg=sum.divide(BigDecimal.valueOf(16),2,BigDecimal.ROUND_HALF_UP);



        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();
            xAxis.add(cityName);
            yAxis.add(indexNum);
        }
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);

        result.put("avg",avg);
//        result.put("cityList",chartsVoList);
        return  result;
    }

    @Override
    public Map<String, Object> getAveragePerMu() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.averagePerMu();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        BigDecimal sum = null;
        BigDecimal avg = null;
        if(chartsVoList == null || chartsVoList.isEmpty()){
            result.put("xAxis",xAxis);
            result.put("yAxis",yAxis);
            result.put("avg",avg);
            return  result;
        }

        List<PreMuChartsVo> chartsVoAllShengList= preMuGenChartsMapper.averagePerMuAllSheng();


        if(chartsVoAllShengList!=null&&chartsVoAllShengList.size()>0){
            sum = chartsVoAllShengList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
        }
        avg=sum.divide(BigDecimal.valueOf(16),2,BigDecimal.ROUND_HALF_UP);

        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();
            xAxis.add(cityName);
            yAxis.add(indexNum);
        }
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);
        result.put("avg",avg);
//        result.put("cityList",chartsVoList);
        return  result;
    }

    @Override
    public Map<String, Object> getRevenue() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.getRevenue();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        BigDecimal sum = null;
        BigDecimal avg = null;
        if(chartsVoList == null ||chartsVoList.isEmpty()){
            result.put("xAxis",xAxis);
            result.put("yAxis",yAxis);
            result.put("avg",avg);
//        result.put("cityList",chartsVoList);
            return  result;
        }

        List<PreMuChartsVo> chartsVoAllShengList= preMuGenChartsMapper.getRevenueAllSheng();


        if(chartsVoAllShengList!=null&&chartsVoAllShengList.size()>0){
            sum = chartsVoAllShengList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
        }
        avg=sum.divide(BigDecimal.valueOf(16),2,BigDecimal.ROUND_HALF_UP);



        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();
            xAxis.add(cityName);
            yAxis.add(indexNum);
        }
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);
        result.put("avg",avg);
//        result.put("cityList",chartsVoList);
        return  result;
    }

    // 各市规上企业收入利润率top10
    @Override
    public Map<String, Object> getCityTop10Srlrl() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.getCityTop10Srlrl();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        BigDecimal sum = null;
        BigDecimal avg = null;
        if(chartsVoList == null ||chartsVoList.isEmpty()){
            result.put("xAxis",xAxis);
            result.put("yAxis",yAxis);
            result.put("avg",avg);
            return  result;
        }

        List<PreMuChartsVo> chartsVoAllShengList= preMuGenChartsMapper.getSrlrlAllSheng();

        if(chartsVoAllShengList != null && chartsVoAllShengList.size()>0){
            sum = chartsVoAllShengList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
        }
        avg = sum.divide(BigDecimal.valueOf(16),2,BigDecimal.ROUND_HALF_UP);

        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();
            xAxis.add(cityName);
            yAxis.add(indexNum);
        }
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);
        result.put("avg",avg);
        return  result;
    }

    @Override
    public Map<String, Object> employees() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.employees();

        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();

            BigDecimal indexNumBigDecimal = new BigDecimal(indexNum);
            indexNumBigDecimal = indexNumBigDecimal.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            xAxis.add(cityName);
            yAxis.add(indexNumBigDecimal.toString());
        }

        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);
//        BigDecimal sum = null;
//        BigDecimal avg = null;
//        if(chartsVoList!=null&&chartsVoList.size()>0){
//            sum = chartsVoList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
//        }
//        avg=sum.divide(BigDecimal.valueOf(chartsVoList.size()),2,BigDecimal.ROUND_HALF_UP);
//        result.put("avg",avg);
//        result.put("cityList",chartsVoList);
        return  result;
    }

    @Override
    public Map<String, Object> fundingInvestment() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.fundingInvestment();

        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();

            String cityName = item.getCityName();
            xAxis.add(cityName);
            yAxis.add(indexNum);
        }

//        BigDecimal sum = null;
//        BigDecimal avg = null;
//        if(chartsVoList!=null&&chartsVoList.size()>0){
//            sum = chartsVoList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
//        }
//        avg=sum.divide(BigDecimal.valueOf(chartsVoList.size()),2,BigDecimal.ROUND_HALF_UP);
//        result.put("avg",avg);
//        result.put("cityList",chartsVoList);
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);
        return  result;
    }

    @Override
    public Map<String, Object> emission() {
        Map<String,Object> result=new HashMap<>();
        List<PreMuChartsVo> chartsVoList= preMuGenChartsMapper.emission();


        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        for(PreMuChartsVo item : chartsVoList){
            String indexNum = item.getIndexNum();
            String cityName = item.getCityName();
            BigDecimal indexNumBigDecimal = new BigDecimal(indexNum);
            indexNumBigDecimal = indexNumBigDecimal.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            xAxis.add(cityName);
            yAxis.add(indexNumBigDecimal.toString());
        }

//        BigDecimal sum = null;
//        BigDecimal avg = null;
//        if(chartsVoList!=null&&chartsVoList.size()>0){
//            sum = chartsVoList.stream().map(i -> new BigDecimal(i.getIndexNum())).reduce(BigDecimal::add).get();
//        }
//        avg=sum.divide(BigDecimal.valueOf(chartsVoList.size()),2,BigDecimal.ROUND_HALF_UP);
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);
        return  result;
    }


    /**
     * <p>
     * 查询备类企业税收及亩均税收情况
     * </p>
     *
     * @return
     */
    @Override
    public Map<String,Object> queryCompanySsAndMjss() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryCompanySsAndMjss();

        //X轴数据
        List<String> xAxis = new ArrayList<>();
        //税收
        List<Object> ssY = new ArrayList<>();
        //亩均税收
        List<Object> mjssY = new ArrayList<>();

        for(BgRespResultVo item : result){
            //获取出企业的名称

            String title = item.getTitle();
            xAxis.add(title);

            //税收
            BigDecimal ss = item.getValueTwo();
            ss = ss == null ? BigDecimal.ZERO : ss.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            ssY.add(ss);

            //用地面积税收
            BigDecimal mjss = item.getValue();
            mjss = mjss == null ? BigDecimal.ZERO : mjss.setScale(2,RoundingMode.HALF_UP);
            mjssY.add(mjss);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("x",xAxis);
        resultMap.put("ssY",ssY);
        resultMap.put("mjssY",mjssY);
        return resultMap;
    }

    /**
     * <p>
     * 查询备类企业利润总额及收入利润率
     * </p>
     *
     * @return
     */
    @Override
    public Map<String,Object> queryCompanyLrzeAndSrlrl() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryCompanyLrzeAndSrlrl();

        //X轴数据
        List<String> xAxis = new ArrayList<>();
        //税收
        List<Object> ssY = new ArrayList<>();
        //亩均税收
        List<Object> mjssY = new ArrayList<>();

        for(BgRespResultVo item : result){
            //获取出企业的名称

            String title = item.getTitle();
            xAxis.add(title);

            //利润总额
            BigDecimal lrze = item.getValueTwo();
            lrze = lrze == null ? BigDecimal.ZERO : lrze.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            ssY.add(lrze);

            //收入利润率
            BigDecimal srlrl = item.getValue();
            srlrl = srlrl == null ? BigDecimal.ZERO : srlrl.setScale(2,RoundingMode.HALF_UP);
            mjssY.add(srlrl);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("x",xAxis);
        resultMap.put("lrzeY",ssY);
        resultMap.put("srlrlY",mjssY);
        return resultMap;
    }

    /**
     * <p>
     * 查询税收前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String,Object> queryTop10Industry() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryTop10Industry();

        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){
            //取出行业名称
            String title = item.getTitle();
            xAxis.add(title);

            BigDecimal value = item.getValue();
            value = value == null ? BigDecimal.ZERO : value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(value);
//            String hyName = (String) item.get("hy_name");
//            xAxis.add(hyName);
//
//            Object sa = item.get("sa");
//            yAxis.add(sa);

        }

        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 查询税收前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String,Object> queryTop10Taxation() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryTop10Taxation();

        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        for(BgRespResultVo item : result){
            String title = item.getTitle();
            xAxis.add(title);

            BigDecimal value = item.getValue();
            value = value == null ? BigDecimal.ZERO : value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(value);
//            String hyName = (String) item.get("hy_name");
//            xAxis.add(hyName);
//
//            Object ss = item.get("ss");
//            yAxis.add(ss);
        }

        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 查询利润总额前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String,Object> queryTop10Lrze() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryTop10Lrze();

        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        for(BgRespResultVo item : result){
            String title = item.getTitle();
            xAxis.add(title);

            BigDecimal value = item.getValue();
            value = value == null ? BigDecimal.ZERO : value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(value);
        }

        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     *  查询销售收入前十的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String,Object> queryTop10Sale() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryTop10Sale();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){

            String title = item.getTitle();
            xAxis.add(title);
            BigDecimal value = item.getValue();
            value = value == null ? BigDecimal.ZERO : value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(value);

//            String hyName = (String) item.get("hy_name");
//            xAxis.add(hyName);
//            Object mi = item.get("mi");
//            yAxis.add(mi);
        }
        Map<String,Object> resultMap = new HashMap<>(16);
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 查询能耗前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10EnergyConsumption() {
        List<Map<String, Object>> result = preMuGenChartsMapper.queryTop10EnergyConsumption();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(Map<String, Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);

            Object tu = item.get("tu");
            if(tu instanceof BigDecimal){
                BigDecimal value = (BigDecimal) tu;
                value = value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
                yAxis.add(value);
            }else{
                BigDecimal value = (BigDecimal) tu;
                value = value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
                yAxis.add(value);
            }
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     *  查询污染物排放前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10Pollution() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryTop10Pollution();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){

            String title = item.getTitle();
            xAxis.add(title);
            BigDecimal value = item.getValue();
            value = value==null ? BigDecimal.ZERO : value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(value);
//            String hyName = (String) item.get("hy_name");
//            xAxis.add(hyName);
//            Object te = item.get("te");
//            yAxis.add(te);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     *     查询研发经费投入前十位的行业
     * </p>
     * @return
     */
    @Override
    public Map<String, Object> queryTop10RdFunding() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryTop10RdFunding();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){

            String title = item.getTitle();
            xAxis.add(title);

            BigDecimal rd = item.getValue();
            rd = rd == null ? BigDecimal.ZERO : rd.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(rd);
//            String hyName = (String) item.get("hy_name");
//            xAxis.add(hyName);
//
//            Object rd = item.get("rd");
//            yAxis.add(rd);

        }

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 查询年平均职工人数前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10NumberEmployees() {
        List<Map<String,Object>> result = preMuGenChartsMapper.queryTop10NumberEmployees();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(Map<String,Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);
            Object ae = item.get("ae");
            if(ae instanceof BigDecimal){
                BigDecimal value = (BigDecimal) ae;
                value = value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
                yAxis.add(value);
            }else{
                BigDecimal value = (BigDecimal) ae;
                value = value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
                yAxis.add(value);
            }

        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 查询亩均税收前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10PerMuTaxRevenue() {
        List<Map<String,Object>> result = preMuGenChartsMapper.queryTop10PerMuTaxRevenue();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        result = result.stream().filter(item -> !StringUtils.isBlank((String)item.get("hy_name"))).collect(Collectors.toList());

        for(Map<String,Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);
            Object ae = item.get("mjss");
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 查询收入利润率前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10Srlrl() {
        List<Map<String,Object>> result = preMuGenChartsMapper.queryTop10Srlrl();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        result = result.stream().filter(item -> !StringUtils.isBlank((String)item.get("hy_name"))).collect(Collectors.toList());

        for(Map<String,Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);
            Object ae = item.get("srlrl");
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 亩均销售收入前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10AverageSalesPerMu() {
        List<Map<String,Object>> result = preMuGenChartsMapper.queryTop10AverageSalesPerMu();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        result = result.stream().filter(item -> !StringUtils.isBlank((String)item.get("hy_name"))).collect(Collectors.toList());
        for(Map<String,Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);
            Object ae = item.get("mjxs");
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 单位能耗税收前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10UnitEnergyConsumption() {
        List<Map<String,Object>> result = preMuGenChartsMapper.queryTop10UnitEnergyConsumption();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        result = result.stream().filter(item -> !StringUtils.isBlank((String)item.get("hy_name"))).collect(Collectors.toList());

        for(Map<String,Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);
            Object ae = item.get("nhss");
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     *  单位污染物排放销售收入前十位行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10PollutantEmissionIncome() {
        List<Map<String,Object>> result = preMuGenChartsMapper.queryTop10PollutantEmissionIncome();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();

        result = result.stream().filter(item -> !StringUtils.isBlank((String)item.get("hy_name"))).collect(Collectors.toList());

        for(Map<String,Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);
            Object ae = item.get("wrwpf");

            BigDecimal value = null;
            if(ae != null){
                if(ae instanceof BigDecimal){
                    BigDecimal value1 = (BigDecimal) ae;
                    value = value1.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
                }else{
                    BigDecimal value1 = (BigDecimal) ae;
                    value = value1.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
                }
            }else{
                value = BigDecimal.ZERO;
            }
            yAxis.add(value);
//            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 研发投入强度前十位的行业
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10RdInvestmentIntensity() {
        List<Map<String,Object>> result = preMuGenChartsMapper.queryTop10RdInvestmentIntensity();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(Map<String,Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);
            Object ae = item.get("yftrqd");
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 全员劳动生产率
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryTop10OverallLaborProductivity() {
        List<Map<String,Object>> result = preMuGenChartsMapper.queryTop10OverallLaborProductivity();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(Map<String,Object> item : result){
            String hyName = (String) item.get("hy_name");
            xAxis.add(hyName);
            Object ae = item.get("qyldscl");

            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     *     各市规上工业企业用地面积(万亩)
     * </p>
     * @return
     */
    @Override
    public Map<String, Object> queryCityCompanyArea() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryCityCompanyArea();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){

            String city = item.getCity();
            xAxis.add(city);
            BigDecimal ae = item.getValue();
            ae = ae == null ? BigDecimal.ZERO : ae.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 各市规上工业企业税收贡献
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryCityCompanySs() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryCityCompanySs();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){

            String city = item.getCity();
            xAxis.add(city);

            BigDecimal ae = item.getValue();
            ae = ae == null ? BigDecimal.ZERO : ae.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 各市规上工业企业利润总额贡献
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryCityCompanyLrze() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryCityCompanyLrze();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){

            String city = item.getCity();
            xAxis.add(city);

            BigDecimal ae = item.getValue();
            ae = ae == null ? BigDecimal.ZERO : ae.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 各市规上工业企业销售收入
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryCityCompanyXssr() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryCityCompanyXssr();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){

            String hyName = item.getCity();
            xAxis.add(hyName);
            BigDecimal ae = item.getValue();
            ae = ae == null ? BigDecimal.ZERO : ae.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }

    /**
     * <p>
     * 各市规上工业企业总能耗
     * </p>
     *
     * @return
     */
    @Override
    public Map<String, Object> queryCityCompanyZnh() {
        List<BgRespResultVo> result = preMuGenChartsMapper.queryCityCompanyZnh();
        List<Object> xAxis = new ArrayList<>();
        List<Object> yAxis = new ArrayList<>();
        for(BgRespResultVo item : result){
            String city = item.getCity();
            xAxis.add(city);
            BigDecimal value = item.getValue();
            value = value == null ? BigDecimal.ZERO : value.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
            yAxis.add(value);
//            String hyName = (String) item.get("city_name");
//            xAxis.add(hyName);
//            Object ae = item.get("znh");
//            yAxis.add(ae);
        }
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("xAxis",xAxis);
        resultMap.put("yAxis",yAxis);
        return resultMap;
    }


}
